package doorwifi.wd.patientsation.peripheral.mainapp.Adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import org.xutils.view.annotation.ViewInject;

import java.util.ArrayList;

import doorwifi.wd.patientsation.peripheral.mainapp.Bean.illnessRoom;
import doorwifi.wd.patientsation.peripheral.mainapp.R;

/**
 * Created by xuhuan on 2017/7/10.
 */

public class illnessDoorAdapter extends RecyclerView.Adapter<illnessDoorAdapter.MyViewHolder> {

    private Context context;
    private ArrayList<illnessRoom> list;
    private LayoutInflater inflater;
    private illnessDoorItemOnclickListener itemOnclickListener;
    private LinearLayout ll;
    private int pos = 0;

    public illnessDoorAdapter(Context context, ArrayList<illnessRoom> list) {
        this.context = context;
        this.list = list;
        inflater = LayoutInflater.from(context);
    }
    public void setPosition(int position){
      pos = position;
    }


    //重写onCreateViewHolder方法，返回一个自定义的ViewHolder
    @Override
    public illnessDoorAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.xh_call_sicked_door_adapter,parent, false);
        MyViewHolder holder= new MyViewHolder(view,itemOnclickListener);
//        x.view().inject(holder,view);
        return holder;
    }

    //填充onCreateViewHolder方法返回的holder中的控件  将数据绑定至ViewHolder
    @Override
    public void onBindViewHolder(illnessDoorAdapter.MyViewHolder holder, int position) {
        illnessRoom room = list.get(position);
//        x.view().inject(holder,view);

        holder.illnessDoorNumber.setText(room.getIllnessNumber());
//        holder.adpater_ll.setBackgroundColor(Color.WHITE);
//
//        if(pos == position){
//            holder.adpater_ll.setBackgroundColor(Color.BLUE);
//        }

    }

    @Override
    public int getItemCount() {
        return list.size();
    }
    @Override
    public int getItemViewType(int position) {
        return position;
    }
    public void setillnessDoorOnItemClickListener(illnessDoorItemOnclickListener listener){
        this.itemOnclickListener = listener;
    }


    class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
        @ViewInject(R.id.call_illnessRoom)
        private TextView illnessDoorNumber;
        @ViewInject(R.id.illnessDoorNumber)
        private ImageView illnessDoorImg;
        @ViewInject(R.id.adpater_ll)
        private LinearLayout adpater_ll;
        private illnessDoorItemOnclickListener ItemOnclickListener;

        public MyViewHolder(View view,illnessDoorItemOnclickListener itemOnclickListener) {
            super(view);
            illnessDoorNumber = (TextView) view.findViewById(R.id.illnessDoorNumber);
            adpater_ll = (LinearLayout) view.findViewById(R.id.adpater_ll);
            this.ItemOnclickListener = itemOnclickListener;
            view.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {
            if(ItemOnclickListener != null){
                ItemOnclickListener.onSickDoorItemClick(v,getLayoutPosition());
            }
        }
    }
    public interface illnessDoorItemOnclickListener{
        public void onSickDoorItemClick(View view,int position);
    }



}
